package com.kabigon.jvm.stack;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.jvm.stack
 * @data 2023/2/18 16:57
 */
class A {

}

class B {

}
public class Demo1_3 {

    static A a = new A();
    static B b = new B();


    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (a) {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (b) {
                    System.out.println("我获得了a and b");
                }

            }
        }).start();

        new Thread(() -> {
            synchronized (b) {
                synchronized (a) {
                    System.out.println("我获得了 a and b");
                }
            }
        }).start();

    }
}
